
import java.awt.*;
import javax.swing.*;

/**
 * @author Logical Solution
 *
 */

class SplashScreen extends JWindow
{
    public SplashScreen(String filename, final JFrame f, int waitTime)
    {
        super(f);
        JLabel l = new JLabel(new ImageIcon(filename));
        getContentPane().add(l, BorderLayout.CENTER);
        pack();
        Dimension screenSize =  Toolkit.getDefaultToolkit().getScreenSize();
        Dimension labelSize = l.getPreferredSize();
        setLocation(screenSize.width/2 - (labelSize.width/2),screenSize.height/2 - (labelSize.height/2));
        /*addMouseListener(new MouseAdapter()//if mouse is pressed, splash screen disappears
        {
        	public void mousePressed(MouseEvent e)
        	{
        		setVisible(false);
        		dispose();
        	}
        });*/
        final int pause = waitTime;
        final Runnable closerRunner = new Runnable()//closeRunner-actual game will get loaded as the 
        {											//splash screen is ready to close
        	public void run()
        	{
        		setVisible(false);
        		dispose();
        		//CutScenes cs = new CutScenes(f);
        		//cs.startCS();
        		ActiveScreen as = new ActiveScreen(f);
        		as.startGame();
        	}
        };
        Runnable waitRunner = new Runnable()
        {
        	public void run()
        	{
        		try
        		{
        			Thread.sleep(pause);
                    SwingUtilities.invokeAndWait(closerRunner);
        		}
        		catch(Exception e)
        		{
        			e.printStackTrace();
                    // can catch InvocationTargetException
                    // can catch InterruptedException
                }
             }
        };
        setVisible(true);
        Thread splashThread = new Thread(waitRunner, "SplashThread");
        splashThread.start();
    }
}
